from django.shortcuts import redirect
from django.utils.deprecation import MiddlewareMixin


class AuthMiddleware(MiddlewareMixin):
    def process_request(self, request):
        if request.path_info == '/login/' or request.path_info == '/logout/' or request.path_info == '/register/' or request.path_info == '/home/':
            return
        info = request.session.get('info')
        if info:
            if request.path_info == '/':
                return redirect('home/')
            return
        else:
            return redirect('/login/')
